export default {
  data() {
    return {
      diy_name: '',
      code: "",
      type_name: "",
      price: "",
      isShowType: false,
      isDisabled: false,
      recharge_tag: ''
    };
  },

  components: {},
  mounted() {
  },
  methods: {
    async getData() {
      let { result, msg, data } = await $http.get("plugin.recharge-code.frontend.index",{},".");
      if (result == 0) return this.$toast(msg);
      this.diy_name = data?.lang?.diy_name || '充值';
      this.fun.setWXTitle(this.diy_name + '码')
    },
    //验证
    verifyCode() {
      if (this.fun.isTextEmpty(this.code)) {
        this.$toast(`请填写${this.diy_name}码`);
        return;
      }

      let that = this;
      $http
        .get(
          "plugin.recharge-code.frontend.code.get-recharge-code",
          { code_key: this.code },
          "验证中..."
        )
        .then(
          function (response) {
            if (response.result == 1) {
              that.isShowType = true;
              that.type_name = response.data.recharge_code.type_name;
              that.price = response.data.recharge_code.price;
              if (response.data.recharge_code.type == 6) {
                // 充值标签类型
                if (response.data.recharge_code.recharge_tag) {
                  that.recharge_tag = response.data.recharge_code.recharge_tag;
                }
              }
            } else {
              that.$dialog.alert({ message: response.msg });
            }
          },
          function (response) {
            // error callback
          }
        );
    },

    //提交
    submit() {
      if (this.fun.isTextEmpty(this.code)) {
        this.$toast(`请填写${this.diy_name}码`);
        return;
      }

      let that = this;
      $http
        .get(
          "plugin.recharge-code.frontend.code.recharge",
          { code_key: this.code },
          `${this.diy_name}中...`
        )
        .then(
          function (response) {
            that.isDisabled = true;
            if (response.result == 1) {
              that.$dialog.alert({ message: response.msg });
              if (response.data.jump_url && response.data.jump_url.length > 0) {
                window.location.href = response.data.jump_url;
              } else {
                that.$router.push(that.fun.getUrl("home", {}));
              }
            } else {
              that.$dialog.alert({ message: response.msg });
            }
          },
          function (response) {
            // error callback
          }
        );
    }
  },
  activated() {
    this.code = this.$route.params.qrCode;
    this.getData();
  }
};
